package uk.co.hs.domain.web;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Index;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import uk.co.hs.domain.generic.UtilisoftGenericDomain;

/**
 * WebRole.
 */
@Entity
@org.hibernate.annotations.Table(appliesTo=WebRole.TABLE_NAME,
                                 indexes={@Index(name=WebRole.TABLE_NAME + "_IDX_1", columnNames={UtilisoftGenericDomain.PK, UtilisoftGenericDomain.VERSION})})
@Table(name=WebRole.TABLE_NAME)
public class WebRole extends UtilisoftGenericDomain<Long>
{
  private static final long serialVersionUID = 1L;

  protected static final String TABLE_NAME = "WEB_ROLE";

  private String mName;
  private List<WebUser> mUsers;

  public WebRole()
  {
    super();
  }

  public WebRole(String aName)
  {
    super();
    mName = aName;
  }

  /**
   * Get the Name.
   * @return The Name.
   */
  @Column(name="NAME", nullable=false, length=20)
  public String getName()
  {
    return mName;
  }

  /**
   * Set the Name.
   * @param aName Name.
   */
  public void setName(String aName)
  {
    mName = aName;
  }

  /**
   * Get all WebUsers for this WebRole.
   *
   * @return
   */
  @OneToMany(targetEntity=WebUser.class, mappedBy="role", cascade=CascadeType.ALL)
  @LazyCollection(LazyCollectionOption.FALSE)
  public List<WebUser> getUsers()
  {
    return mUsers;
  }

  public void setUsers(List<WebUser> aUsers)
  {
    mUsers = aUsers;
  }
}
